import { catchAwait } from "utils-lib-js";
import { wechaty } from "./index.js";
import { module } from "../utils/index.js";
export const onMessage = async (IMsg) => {
  const { botInfo } = wechaty; // 登录信息
  if (!!!botInfo) return;
  const msgResult = await IMsg.text();
  const temp = msgResult.split(botInfo.name());
  if (!!!temp[0] === "@" || !!!temp[1]) return;
  module.gpt && gptModel({ IMsg, text: temp[1] });
};

export const gptModel = async ({ IMsg, text }) => {
  console.log(`收到消息: ${text}`);
  const [err, res] = await catchAwait(module.gpt.conversation({ msg: text }));
  console.log(`发送消息: ${err ?? res.text}`);
  IMsg.say(err ?? res.text);
};
